package com.ruoyi.web.controller.system;

import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;

import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysDataAuthConfig;
import com.ruoyi.system.service.ISysDataAuthConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据权限配置Controller
 *
 * @author 马帅
 * @date 2024-06-13
 */
@RestController
@RequestMapping("/system/dataAuthConfig")
public class SysDataAuthConfigController extends BaseController {
    @Autowired
    private ISysDataAuthConfigService sysDataAuthConfigService;


    /**
     * 查询数据权限配置列表-分页
     */
    @PreAuthorize("@ss.hasPermi('system:dataAuthConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam Map<String, Object> params) {
        IPage<SysDataAuthConfig> page = sysDataAuthConfigService.selectSysDataAuthConfigPage(params);
        return getDataTableMp(page);
    }

    /**
     * 导出数据权限配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:dataAuthConfig:export')")
    @Log(title = "数据权限配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody Map<String, Object> params) {
        IPage<SysDataAuthConfig> page = sysDataAuthConfigService.selectSysDataAuthConfigPage(params);
        ExcelUtil<SysDataAuthConfig> util = new ExcelUtil<SysDataAuthConfig>(SysDataAuthConfig.class);
        util.exportExcel(response, page.getRecords(), "数据权限配置数据");
    }

    /**
     * 获取数据权限配置详细信息-根据主键查询
     */
    @PreAuthorize("@ss.hasPermi('system:dataAuthConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(sysDataAuthConfigService.selectSysDataAuthConfigById(id));
    }

    /**
     * 新增数据权限配置
     */
    @PreAuthorize("@ss.hasPermi('system:dataAuthConfig:add')")
    @Log(title = "数据权限配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDataAuthConfig sysDataAuthConfig) {
        return toAjax(sysDataAuthConfigService.insertSysDataAuthConfig(sysDataAuthConfig));
    }

    /**
     * 修改数据权限配置
     */
    @PreAuthorize("@ss.hasPermi('system:dataAuthConfig:edit')")
    @Log(title = "数据权限配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDataAuthConfig sysDataAuthConfig) {
        return toAjax(sysDataAuthConfigService.updateSysDataAuthConfig(sysDataAuthConfig));
    }

    /**
     * 删除数据权限配置
     */
    @PreAuthorize("@ss.hasPermi('system:dataAuthConfig:remove')")
    @Log(title = "数据权限配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(sysDataAuthConfigService.deleteSysDataAuthConfigByIds(ids));
    }

}
